package com.bajie.bjlisten.sevice;

import com.bajie.bjlisten.entity.BjInvite;
import com.bajie.bjlisten.mapper.BjInviteMapper;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
public class BjInviteService {
    @Autowired
    BjInviteMapper bjInviteMapper;
    private static final Logger log = LoggerFactory.getLogger("adminLogger");


    @Transactional
    public int saveBjInvite(BjInvite bjInvite) {
        int value = bjInviteMapper.saveBjInvite(bjInvite);
        if (value > 0)
            return value;
        else
            throw new RuntimeException();

    }

    /**
     * //根据邀请人查询被邀请的人
     * @param parentId
     * @param offset
     * @param limit
     * @return
     */
    public List<BjInvite> findByParentId(String parentId,Integer offset,Integer limit){
        return bjInviteMapper.findByParentId(parentId,offset,limit);
    }


    //根据查询今天邀请的用户的收入
    public Map<String, BigDecimal> findByParentIdAndToday(String parentId){
        return bjInviteMapper.findByParentIdAndToday(parentId);
    }

    //查询昨天邀请的收入
    public Map<String, BigDecimal> findByParentIdAndYesterday(String parentId){
        return bjInviteMapper.findByParentIdAndYesterday(parentId);
    }

    //查询用户所有邀请的用户的收入
    public Map<String, BigDecimal> findAllByParentId(String parentId){
        return bjInviteMapper.findAllByParentId(parentId);
    }



}
